package com.example.controller;

import com.example.entity.Notice;
import com.example.entity.example.*;
import com.example.entity.vo.NoticeVO;
import com.example.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/welcome")
public class WelcomeController {

    @Autowired
    UserService userService;

    @Autowired
    DeptService deptService;

    @Autowired
    JobService jobService;

    @Autowired
    EmployeeService employeeService;

    @Autowired
    RoleService roleService;

    @Autowired
    UploadFileService uploadFileService;

    @Autowired
    NoticeService noticeService;

    @Autowired
    NoticeController noticeController;

    @RequestMapping("/page.html")
    public String welcomePage(ModelMap modelMap) {
        long userCount = userService.getCountByExample(new UserExample());
        long deptCount = deptService.getCountByExample(new DeptExample());
        long jobCount = jobService.getCountByExample(new JobExample());
        long employeeCount = employeeService.getCountByExample(new EmployeeExample());
        long roleCount = roleService.getCountByExample(new RoleExample());
        long uploadFileCount = uploadFileService.getCountByExample(new UploadFileExample());
        modelMap.addAttribute("userCount", userCount);
        modelMap.addAttribute("deptCount", deptCount);
        modelMap.addAttribute("jobCount", jobCount);
        modelMap.addAttribute("employeeCount", employeeCount);
        modelMap.addAttribute("roleCount", roleCount);
        modelMap.addAttribute("uploadFileCount", uploadFileCount);

        List<Notice> noticeList = noticeService.getByExampleWithLimit(null, null, null, 1, 10);
        List<NoticeVO> noticeVOList = new ArrayList<>(noticeList.size());
        for (Notice notice : noticeList) {
            noticeVOList.add(noticeController.transformToNoticeVO(notice));
        }
        modelMap.addAttribute("noticeVOList", noticeVOList);
        return "include/welcome";
    }
}
